package com.jjb.www.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.shape.layout.ShapeLinearLayout;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.http.api.CurriculumSortApi;
import com.jjb.www.http.api.PayDetailsApi;
import com.jjb.www.http.glide.GlideApp;
import com.jjb.www.http.httputil.HttpUtis;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.ui.fragment.CourseListFragment;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/03/01
 *    desc   : 支付详情
 */
public class PayDetailsActivity extends AppActivity {

    private String id = "";
    private ShapeImageView mImgUrl;
    private ShapeTextView mTvName;
    private ShapeTextView mTvInvoiceMoney;
    private ShapeTextView mTvOrderTypeName;
    private ShapeTextView mTvOrderNumber;
    private ShapeTextView mTvCreateTime;
    private ShapeTextView mPayMethodId;
    private ShapeTextView mTvThreeOrderNumber;
    private ShapeTextView mTvFpType;
    private ShapeTextView mTvLook;
    private ShapeLinearLayout mLlView;
    //开票状态
    private Integer invoice_status =0;
    private PayDetailsApi.Bean bean;
    //发票下载地址
    private String url = "";





    @Override
    protected int getLayoutId() {
        return R.layout.activity_pay_details;
    }

    @Override
    protected void initView() {
        mImgUrl = findViewById(R.id.img_url);
        mTvName = findViewById(R.id.tv_name);
        mTvInvoiceMoney = findViewById(R.id.tv_invoice_money);
        mTvOrderTypeName = findViewById(R.id.tv_order_type_name);
        mTvOrderNumber = findViewById(R.id.tv_order_number);
        mTvCreateTime = findViewById(R.id.tv_create_time);
        mPayMethodId = findViewById(R.id.pay_method_id);
        mTvThreeOrderNumber = findViewById(R.id.tv_three_order_number);
        mTvFpType = findViewById(R.id.tv_fp_type);
        mTvLook = findViewById(R.id.tv_look);
        mLlView = findViewById(R.id.ll_view);
        setOnClickListener(mTvLook);
    }

    @Override
    public void onClick(View view) {
        if (view==mTvLook){
            //0可开票 1开票中 2已开票 3开票失败  4开票过期
            if (invoice_status==0){
                Intent intent = new Intent();
                intent.putExtra("price",bean.getPay_money());
                intent.setClass(getContext(),InvoiceActivity.class);
                startActivity(intent);
            }else if (invoice_status==1){

            }else if (invoice_status==2){
                HttpUtis.downLoad(PayDetailsActivity.this,PayDetailsActivity.this,url);
            }else if (invoice_status==3){

            }else if (invoice_status==4){

            }
        }
    }

    @Override
    protected void initData() {
        id = getString("id");
        EasyHttp.get(this)
                .api(new PayDetailsApi()
                .setId(id))
                .request(new HttpCallback<HttpData<PayDetailsApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<PayDetailsApi.Bean> data) {
                        bean = data.getData();
                        invoice_status = bean.getInvoice_status();
                        url = bean.getUrl();
                        GlideApp.with(getContext())
                                .load(data.getData().getPhoto())
                                .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                                .into(mImgUrl);
                        mTvName.setText(bean.getName());
                        mTvInvoiceMoney.setText("¥"+bean.getPay_money());
                        mTvOrderTypeName.setText(bean.getOrder_type_name());
                        mTvOrderNumber.setText(bean.getOrder_number());
                        mTvCreateTime.setText(bean.getCreate_time());
                        mPayMethodId.setText(bean.getPay_method_id());
                        mTvThreeOrderNumber.setText(bean.getThree_order_number());
                        //0可开票 1开票中 2已开票 3开票失败  4开票过期
                        if (bean.getInvoice_status()==0){
                            mTvLook.setText("¥"+bean.getPay_money()+"申请开票");
                            mTvLook.getShapeDrawableBuilder().setSolidColor(ContextCompat.getColor(getContext(), R.color.color_3675FE)).intoBackground();
                            mTvLook.getTextColorBuilder()
                                    .setTextColor(ContextCompat.getColor(getContext(), R.color.white))
                                    .intoTextColor();
                        }else if (bean.getInvoice_status()==1){
                            mTvLook.setText("开票中");
                            mTvLook.getShapeDrawableBuilder().setSolidColor(ContextCompat.getColor(getContext(), R.color.color_F1F1F1)).intoBackground();
                            mTvLook.getTextColorBuilder()
                                    .setTextColor(ContextCompat.getColor(getContext(), R.color.color_999999))
                                    .intoTextColor();
                        }else if (bean.getInvoice_status()==2){
                            mTvLook.setText("查看电子发票");
                            mTvLook.getShapeDrawableBuilder().setSolidColor(ContextCompat.getColor(getContext(), R.color.color_3675FE)).intoBackground();
                            mTvLook.getTextColorBuilder()
                                    .setTextColor(ContextCompat.getColor(getContext(), R.color.white))
                                    .intoTextColor();
                        }else if (bean.getInvoice_status()==3){
                            mTvLook.setText("¥"+bean.getPay_money()+"申请开票");
                            mTvLook.getShapeDrawableBuilder().setSolidColor(ContextCompat.getColor(getContext(), R.color.color_3675FE)).intoBackground();
                            mTvLook.getTextColorBuilder()
                                    .setTextColor(ContextCompat.getColor(getContext(), R.color.white))
                                    .intoTextColor();
                        }else if (bean.getInvoice_status()==4){
                            mLlView.setVisibility(View.GONE);
                        }

                    }

                });
    }
}